#include <stdio.h>
/*
    单链表动态存储分配版
*/
struct s_list{
    int data;
    struct s_list *next;
};

int main(void)
{
    struct s_list *head,*p;//声明头指针和遍历指针
    //给第一个节点动态分配内存空间并使头结点指向第一个节点
    head = (struct s_list *)malloc(sizeof(struct s_list));
    head->data = 1;//给第一个节点的数据域赋值
    head->next = (struct s_list *)malloc(sizeof(struct s_list));
    head->next->data = 2;
    head->next->next = (struct s_list *)malloc(sizeof(struct s_list));
    head->next->next->data = 3;
    head->next->next->next = NULL;
    p = head;
    while(p){
        printf("%p\t%d\t%p", p, p->data, p->next);
        p = p->next;
    }
    return 0;
}

void create_list_v1(struct s_list **headp, int *p)
{
    struct s_list *loc_head = NULL, *tail;
    if(p[0] == 0);
    else{
        loc_head = (struct s_list *)malloc(sizeof(struct s_list));
        loc_head->data = *p++;
        tail = loc_head;
        while(*p){
            tail->next=(struct s_list *)malloc(sizeof(struct s_list));
            tail=tail->next;
            tail->data=*p++;
        }
        tail->next=NULL;
    }
    *headp=loc_head;
}
